Skip to content

feat: multi-ext-versions-pgrcron #1549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open

Conversation

samrose
Copy link
Collaborator

@samrose samrose commented Apr 15, 2025

What kind of change does this PR introduce?

Incremental repackage of pg extensions to include all known installed branches, starting with pg cron. This release will include 1.3, 1.4, 1.6

Older versions only support pg 15, and so are only covered with pg 15, and WILL NOT be installed along with pg 17+ or oriole releases. This PR includes a patch for 1.3.1 version due to incompat with 15.8

We will test to see that this still on restore, across all versions.

@samrose samrose requested review from a team as code owners April 15, 2025 18:53
@samrose samrose changed the title feat: multi-ext-versios-pgrcron feat: multi-ext-versions-pgrcron Apr 15, 2025
@samrose
Copy link
Collaborator Author

samrose commented Apr 18, 2025

@Crispy1975 I was going to wait to merge this until you had a chance to test it out in staging. Just wanted to add this as a status on this PR.

@samrose samrose force-pushed the multi-ver-ext-pgr-cron branch from bd5d5ca to 3d203ed Compare April 24, 2025 15:27
@samrose
Copy link
Collaborator Author

samrose commented Apr 24, 2025

We needed to handle the lib that pg_cron worker uses on start of postgres server cluster.

So, we're going to add a file pg_extensions.json and read that, and set the alias before postgres starts to account for the worker.

@steve-chavez
Copy link
Member

We needed to handle the lib that pg_cron worker

@samrose Could you elaborate on that? Which lib does it need and why do we require a pg_extension.json file? Can't the dependency by fully managed by a Nix expression?

@samrose
Copy link
Collaborator Author

samrose commented Apr 24, 2025

We needed to handle the lib that pg_cron worker

@samrose Could you elaborate on that? Which lib does it need and why do we require a pg_extension.json file? Can't the dependency by fully managed by a Nix expression?

It already is. The nix dependency packaging part is done.

However, the AMI and Nix package won't know which version is being restored to. So, when a restore is triggered, the version that was active at backup time will be recorded into the infrastructure middleware db, and then it will be written as a datapoint to a file on restore. Then, the postgres prestart script will read that version number, and re-alias the installed package to the expected version, because postgres starts pg_cron worker on startup.

@steve-chavez
Copy link
Member

However, the AMI and Nix package won't know which version is being restored to. So, when a restore is triggered, the version that was active at backup time will be recorded into the infrastructure middleware db, and then it will be written as a datapoint to a file on restore.

Will the above be relevant even when we transition to physical backups?

@samrose
Copy link
Collaborator Author

samrose commented Apr 24, 2025

We needed to handle the lib that pg_cron worker

@samrose Could you elaborate on that? Which lib does it need and why do we require a pg_extension.json file? Can't the dependency by fully managed by a Nix expression?

We package all of known installed versions of pg_cron, then when a project is restored from a backup file, a specific version was in use when the backup happened. So, on restore, we can switch alias to that nix packaged version, and it will restore without error AND the pg_cron worker that starts up when postgres starts up will use the right version.

@samrose
Copy link
Collaborator Author

samrose commented Apr 24, 2025

However, the AMI and Nix package won't know which version is being restored to. So, when a restore is triggered, the version that was active at backup time will be recorded into the infrastructure middleware db, and then it will be written as a datapoint to a file on restore.

Will the above be relevant even when we transition to physical backups?

yes, for sure @Crispy1975 is working with me on this now and can confirm. The same issue may affect timescale too

Extensions that do not start a worker at postgres startup likely won't have this issue and will just be able to find and use the packaged version it needs (we'll find out when we test it).

THIS pr is for pg_cron. We are packaging and releasing these multiversion one extension at a time.

@samrose
Copy link
Collaborator Author

samrose commented Apr 24, 2025

THIS pr is for pg_cron. We are packaging and releasing these multiversion one extension at a time.

and pg_cron definitely needs this extra handling, due to worker starting at pg server startup

@samrose
Copy link
Collaborator Author

samrose commented Apr 24, 2025

all of this multi version work will be solely for physical backup approach fwiw. so, anything we do in multiversion extension pkg will be due to initial testing and confirming we need to do it for physical backups.

@steve-chavez
Copy link
Member

steve-chavez commented Apr 24, 2025

yes, for sure @Crispy1975 is working with me on this now and can confirm. The same issue may affect timescale too

Got it. Thanks for clarifying.

Extensions that do not start a worker at postgres startup likely won't have this issue and will just be able to find and use the packaged version it needs (we'll find out when we test it).

Let me backup this a bit. So the root problem is that the restore doesn't capture the C library version right? (that's where the code for background worker is)

And this is because it just does CREATE EXTENSION pg_cron <version>? (and this only contains the SQL code)

@samrose
Copy link
Collaborator Author

samrose commented Apr 24, 2025

yes, for sure @Crispy1975 is working with me on this now and can confirm. The same issue may affect timescale too

Got it. Thanks for clarifying.

Extensions that do not start a worker at postgres startup likely won't have this issue and will just be able to find and use the packaged version it needs (we'll find out when we test it).

Let me backup this a bit. So the root problem is that the restore doesn't capture the C library version right? (that's where the code for background worker is)

And this is because it just does CREATE EXTENSION pg_cron <version>?

the restore captures it, but the restore can't read prior to preforming the restore because it is a binary file. So, our solution is to simultaneously record the version that was installed at backup time, and then make that data available as a file when the restore is run, the prestart can read it, and can alias pg_cron to the right lib before postgres starts. Then, restore should take care of the rest (we are testing this theory now).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants